const { PrismaClient } = require('@prisma/client');
const bcryptjs = require('bcryptjs');
const { createId } = require('@paralleldrive/cuid2');

const prisma = new PrismaClient();

async function createAdminUser() {
  try {
    const hashedPassword = await bcryptjs.hash('password123', 10);
    
    const userId = createId();
    const secretsId = createId();
    
    const user = await prisma.user.create({
      data: {
        id: userId,
        name: '管理员',
        email: 'admin@example.com',
        username: 'admin',
        locale: 'zh-CN',
        emailVerified: true,
        provider: 'email',
        secrets: {
          create: {
            id: secretsId,
            password: hashedPassword
          }
        }
      },
      include: {
        secrets: true
      }
    });
    
    console.log('管理员用户创建成功:', user);
  } catch (error) {
    console.error('创建用户失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

createAdminUser(); 